/*
 *  serialDevice.h
 *  zinaApp001
 *
 *  Created by Arne Boon on 1/24/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef _SERIAL_DEVICE
#define _SERIAL_DEVICE

#include "ofMain.h"
#include "ofEvents.h"

#define NUM_BYTES	8				//number of bytes to read as one message


//-----------------------------------------------
class EventArgsJoystick : public ofEventArgs
{
public:
	int joystickNum;
	int joystickPinNum;
	bool joystickStatus;
	
};

//-----------------------------------------------
class SerialDevice : public ofBaseApp {

	public:
	
	enum DIRECTION {		//int
		DIRECTION_UP,		//0
		DIRECTION_DOWN,		//1
		DIRECTION_LEFT,		//2
		DIRECTION_RIGHT,	//3
		DIRECTION_STOP		//4
	};
	
	SerialDevice();
	~SerialDevice();

	void setup(int _deviceId, int _baud);
	void update();
	
	void close();

	//--key events
	EventArgsJoystick argsJoystick;
	ofEvent<EventArgsJoystick> onJoystickMoved;
	

private:

	//--ofSerial
	ofSerial serial;

	//--vars
	unsigned char bytesReturned[NUM_BYTES];
	int bytesRequired;
	int bytesRemaining;
	int countCycles;

	int waitingCycles;

};

#endif
